<?php 
session_start();

$user = $_SESSION['username'];
if (!$user) { header('location: login.php'); exit; }

$sort = $_GET['sort'];
$filter = $_POST['filter_field']; if (!$filter) { $filter = $_GET['filter_field'];}
$filter_data = $_POST['dataa']; if (!$filter_data) { $filter_data = $_GET['dataa'];}
include "../../includes/functions.php";
echo db_connect();

 /// put auth check here


$day = date("l"); //echo $day;

 ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Playlists</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

</script>
<script type="text/javascript" src="../../calendar_picker.js"></script>      
</head>

<body bgcolor="#eeeeee">
<a href='index.php'><< ADMINISTRATION Home </a><br><br>
<h1>REPORT: Shows with playlists</h1>
<p><?=$msg?></p>

<?php


$today = substr(date('Y-m-d'),0,10); //echo "today: $today";


$start_date = '2009-09-06 00:00:00'; 
  
	$so_query = 
	'SELECT show_id, show_name, show_occurrance_id, start_time, `date` FROM show_events
		WHERE `date` > "'.$start_date.'"	
		ORDER BY `date` DESC, start_time'; 
		//echo "<br> $so_query<br>";
	$so_result = mysql_query ($so_query); if (!$so_result) die("error with so query".mysql_error().$so_query);
	while ($so_row = mysql_fetch_array ($so_result)) {
	
	
	
	 $so_show_id = $so_row[0]; 
	 $so_show_name = $so_row[1];
	 $so_start_time = $so_row[3];
	 $so_date = $so_row[4];  $display_date= date('F d, Y',strtotime($so_date));
	 $so_date_chopped = substr($so_date,0,10); 
	
	if ($temp != $so_date) { echo "<div class='report_subhead'>" .date('l',strtotime($so_date)) . " $display_date" . "</div>"; $temp = $so_date; }
	
	
	
	echo "<div class='report_item'> $so_start_time :: $so_show_name ";  
	
	$pl_query = "SELECT * FROM playlists WHERE show_id = '$so_show_id' AND datetime LIKE '$so_date_chopped%' LIMIT 1";  //echo "<br>$pl_query";
	$pl_result = mysql_query ($pl_query); if (!$pl_result) die("error with so query".mysql_error().$pl_query);
	$pl_row = mysql_fetch_array ($pl_result);
	$pl_playlist_id = $pl_row [0];
	
	$item_query = 'select playlist_item_id from playlist_items where playlist_id = "'.$pl_playlist_id.'"';
	$item_result= mysql_query($item_query);
	$e=0;
	while ($item_row= mysql_fetch_array($item_result))  {
		$item = $item_row[0];
		$e++;
	}
	if ($e) {$col = "color:black;";} else {$col = "color:blue;";}  
	$tracks_count = " <span style='$col;'>[$e tracks]</span>";
	
	if ($pl_playlist_id && $e)  echo "   :: <a href='../playlist_new.php?show_id=$so_show_id&playlist_id=$pl_playlist_id' target='blank'><span style='color:red; font-weight:bold;'>Playlist $tracks_count</span></a>";
	echo "</div>"; 
	}




 



?>  

</body>
</html>
